package com.googlecode.trabhci2011.stockmarket.client;

import java.util.HashMap;
import java.util.Vector;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.googlecode.trabhci2011.stockmarket.shared.StockDataEntry;

public class StockCallback implements AsyncCallback<Vector<String>> {
	
	HashMap <String, Vector<StockDataEntry>> stockMap = null;
	StockCanvas drawCanvas = null;
	public StockCallback(HashMap <String, Vector<StockDataEntry>> s, StockCanvas c){
		stockMap = s;
		drawCanvas = c;
	}

	@Override
	public void onFailure(Throwable caught) {
		GWT.log("something went wrong:", caught);

	}

	@Override
	public void onSuccess(Vector<String> result) {
		stockMap.clear();
		for(String stringResult : result){
			//stockMap.put(key, value) 
			StockDataEntry dataEntry= new StockDataEntry(stringResult);

			Vector<StockDataEntry> myVector = stockMap.get(dataEntry.getIndex());
			if(myVector == null){
				myVector = new Vector<StockDataEntry>();
				stockMap.put(dataEntry.getIndex(), myVector);
			}
			myVector.add(dataEntry);
		}
		drawCanvas.update();
	}

}
